﻿using Minecraft.Config.Csv.CsvCls;
using Minecraft.Model.Mod;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minecraft.Config
{
	/// <summary>
	/// Csv配置
	/// </summary>
	public partial class CsvConfig
	{
		public static List<ModMapTransformInfo> modMapTransformInfoList = new List<ModMapTransformInfo>();
		private static void InstallAfter()
		{
			//TransformList(ref modMapTransformInfoList, new List<string> { MinecraftConfig.BaseMapId });
			TransformDict(ref modMapTransformInfoList, new List<string> { MinecraftConfig.BaseMapId });
		}

		/// <summary>
		/// mod map 实体转换（包含layer）
		/// </summary>
		/// <param name="mod_MapList"></param>
		/// <returns></returns>
		private static void TransformDict(ref List<ModMapTransformInfo> modMapTransformInfoList, List<string> depotIdList, int layerBig = 1)
		{
			if (depotIdList != null && depotIdList.Any())
			{
				var thelayerSmall = 0;
				foreach (var depotId in depotIdList)
				{
					var thelayerBig = layerBig;
					thelayerSmall++;
					List<Mod_Map> mod_MapList = mapDict.Where(m => m.Value.Id == depotId || m.Value.Depot == depotId).Select(m => m.Value).ToList();
					if (mod_MapList != null && mod_MapList.Any())
					{
						var newModMapTransformInfoLi = mod_MapList.Select(m => new ModMapTransformInfo()
						{
							mapId = m.Id,
							mapName = m.Name,
							mapPoint3 = m.point3,
							danger = m.danger_Convert,
							level = m.level_Convert,
							If_depot = m.If_depot_Convert,
							depotId = m.Depot,
							nextDepotId = m.Next_depot,
							layerBig = thelayerBig,
							layerSmall = thelayerSmall,
						}).ToList();
						modMapTransformInfoList.AddRange(newModMapTransformInfoLi);
						depotIdList = mod_MapList.FirstOrDefault(m => m.If_depot_Convert).GetNextDepotIdList();
						TransformDict(ref modMapTransformInfoList, depotIdList, thelayerBig + 1);
					}
				}
			}
		}
	}
}
